package com.hehua.CompositePattern;

import java.util.ArrayList;

public class Folder extends AbstractFile {

    //定义集合fileList,用于存储AbstractFile类型的成员
    private ArrayList<AbstractFile> fileList = new ArrayList<AbstractFile>();

    private String name;

    public Folder(String name) {
        this.name = name;
    }

    @Override
    public void add(AbstractFile abstractFile) {
        fileList.add(abstractFile);
    }

    @Override
    public void remove(AbstractFile abstractFile) {
        fileList.remove(abstractFile);
    }

    @Override
    public AbstractFile getChild(int i) {
        return fileList.get(i);
    }

    @Override
    public void killVirus() {
        //模拟杀毒
        System.out.println("----------对文件夹" + name + "进行杀毒");
        //递归调用成员构件的killVirus方法
        for (AbstractFile abstractFile : fileList) {
             abstractFile.killVirus();
        }
    }
}
